﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.SharePoint.Administration;

namespace SharePointCommander.Model.TreeView
{
    public class SCServer : SCTreeViewItem<SPServer>
    {
        public SCServer(SCTreeViewItem parent, SPServer server)
            : base(parent, server)
        {
            this.Header = server.DisplayName;
            Expanded += new System.Windows.RoutedEventHandler(SCServer_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCServer_Expanded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!ItemsSource.OfType<SCProperties>().Any())
            {
                ItemsSource = new[] { 
                    new SCServiceInstanceCollection(this, SPObject.ServiceInstances) as TreeViewItem,
                    new SCProperties(this, SPObject.Properties) as TreeViewItem
                };
            }
        }
    }
}
